home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 25 / AACD 25.iso / AACD / Magazine / Backups / FBackNG / getreg.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-30  |  1.1 KB  |  78 lines

  1. // getreg.c
  2. // Function to get the user out of the keyfile
  3. // Must return zero otherwise something is wrong
  4.  
  5. #include <fcntl.h>
  6. #include <exec/types.h>
  7. #include <exec/exec.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10.  
  11. int GetRegisteredUser(char *filename, char *user)
  12. {
  13.  
  14.         int h;
  15.         int i;
  16.         unsigned char x;
  17.         int cs;
  18.         int l;
  19.  
  20.         h=open(filename,O_RDONLY);
  21.         if(h<0) 
  22.                 return(-1);
  23.  
  24.         cs=0;
  25.         for(i=0;i<200;i++)
  26.     {
  27.             read(h,&x,1);
  28.             cs=cs+x;
  29.     }
  30.  
  31.         read(h,&x,1);
  32.         cs=cs%256;
  33.         if(x!=cs) 
  34.     {
  35.             close(h);
  36.             return(-1);
  37.     }
  38.  
  39.         read(h,&x,1);
  40.         l=x;
  41.  
  42.         cs=0;
  43.         for(i=0;i<l;i++)
  44.     {
  45.             read(h,&x,1);
  46.             cs=cs+x;
  47.             user[i]=x-85-i;
  48.     }    
  49.  
  50.         user[l]=0;
  51.         read(h,&x,1);
  52.         cs=cs%256;
  53.         if(cs!=x) 
  54.     {
  55.             close(h);
  56.             return(-3);
  57.     }
  58.  
  59.         cs=0;
  60.         for(i=0;i<200;i++)
  61.     {
  62.             read(h,&x,1);
  63.             cs=cs+x;
  64.     }
  65.  
  66.         read(h,&x,1);
  67.         cs=cs%256;
  68.         if(x!=cs) 
  69.     {
  70.             close(h);
  71.             return(-2);
  72.     }
  73.  
  74.         close(h);
  75.         return(0);
  76. }
  77. // The End
  78.